package com.lhc.nacosconsumer.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lhc.nacosconsumer.entity.Stock;
import com.lhc.nacosconsumer.mapper.StockMapper;
import com.lhc.nacosconsumer.service.StockService;
import org.springframework.stereotype.Service;

/**
 * @author liuchaoqun
 * @date 2022/6/18
 * @Description 库存业务
 */
@Service
public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements StockService {

    @Override
    public Boolean reduce(Long id) {

        Stock stock = baseMapper.selectByMenuId(id);
        if (stock.getNum() < 1) {
            throw new RuntimeException("库存不足无法扣减");
        }

        stock.setNum(stock.getNum() - 1);
        baseMapper.updateById(stock);
        return Boolean.TRUE;
    }

}
